package com.gss.module.generator.entity;

import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.setting.dialect.Props;
import lombok.Data;

/**
 * @author DYang
 * @date 2023/5/25
 * 读取默认配置文件
 */
@Data
public class DefaultConfigInfo {

    private static DefaultConfigInfo instance;

    /**
     * 根目录
     */
    private String rootDir;

    /**
     * 实体类
     */
    private String entityDir;

    /**
     * sql实体类
     */
    private String sqlDir;

    /**
     * controller实体类
     */
    private String controllerDir;

    /**
     * service实体类
     */
    private String serviceDir;

    /**
     * serviceImpl实体类
     */
    private String serviceImplDir;

    /**
     * mapper实体类
     */
    private String mapperDir;

    /**
     * mapper-xml实体类
     */
    private String mapperXmlDir;


    public static DefaultConfigInfo getInstance(){
        if (instance != null) {
            return instance;
        }
        ClassPathResource resource = new ClassPathResource("classpath:generator_config.yml");
        // 创建Props对象，加载YAML文件内容
         Props props = new Props(resource.getFile(), "UTF-8");

        String rootDir = props.getStr("root-dir");
        String entityDir = rootDir + "/" + props.getStr("entity");
        String sqlDir = rootDir + "/" +  props.getStr("sql");
        String controllerDir = rootDir + "/" +  props.getStr("controller");
        String serviceDir = rootDir + "/" +  props.getStr("service");
        String serviceImplDir = rootDir + "/" +  props.getStr("serviceImpl");
        String mapperDir = rootDir + "/" +  props.getStr("mapper");
        String mapperXmlDir = rootDir + "/" +  props.getStr("mapper-xml");

        instance = new DefaultConfigInfo();
        instance.setRootDir(rootDir);
        instance.setEntityDir(entityDir);
        instance.setServiceDir(serviceDir);
        instance.setServiceDir(serviceDir);
        instance.setServiceImplDir(serviceImplDir);
        instance.setSqlDir(sqlDir);
        instance.setControllerDir(controllerDir);
        instance.setMapperDir(mapperDir);
        instance.setMapperXmlDir(mapperXmlDir);

        return instance;
    }

    public static void main(String[] args) {
        DefaultConfigInfo info = getInstance();
        System.out.println(info);
    }
}
